home *** CD-ROM | disk | FTP | other *** search
Wrap
RRRRWWWWTTTTVVVVaaaallllHHHHaaaasssshhhhMMMMuuuullllttttiiiiMMMMaaaapppp((((3333CCCC++++++++)))) RRRRWWWWTTTTVVVVaaaallllHHHHaaaasssshhhhMMMMuuuullllttttiiiiMMMMaaaapppp((((3333CCCC++++++++)))) NNNNaaaammmmeeee RWTValHashMultiMap<K,T,H,EQ> - Rogue Wave library class SSSSyyyynnnnooooppppssssiiiissss #include <rw/tvhmmap.h> RWTValHashMultiMap<K,T,H,EQ> m; SSSSttttaaaannnnddddaaaarrrrdddd CCCC++++++++ LLLLiiiibbbbrrrraaaarrrryyyy DDDDeeeeppppeeeennnnddddeeeennnntttt!!!! RRRRWWWWTTTTVVVVaaaallllHHHHaaaasssshhhhMMMMuuuullllttttiiiiMMMMaaaapppp requires the Standard C++ Library. DDDDeeeessssccccrrrriiiippppttttiiiioooonnnn This class maintains a collection of keys, each with an associated item of type TTTT. These pairs are stored according to a hash object of type HHHH. HHHH must provide a hash function on elements of type KKKK via a public member uuuunnnnssssiiiiggggnnnneeeedddd lllloooonnnngggg ooooppppeeeerrrraaaattttoooorrrr(((())))((((ccccoooonnnnsssstttt KKKK&&&& xxxx)))) ccccoooonnnnsssstttt Equivalent keys within the collection will be grouped together based on an equality object of type EEEEQQQQ. EEEEQQQQ must ensure this grouping via public member bbbboooooooollll ooooppppeeeerrrraaaattttoooorrrr(((())))((((ccccoooonnnnsssstttt KKKK&&&& xxxx,,,, ccccoooonnnnsssstttt KKKK&&&& yyyy)))) ccccoooonnnnsssstttt which should return ttttrrrruuuueeee if xxxx and yyyy are equivalent. RRRRWWWWTTTTVVVVaaaallllHHHHaaaasssshhhhMMMMuuuullllttttiiiiMMMMaaaapppp<<<<KKKK,,,,TTTT,,,,HHHH,,,,EEEEQQQQ>>>> may contain multiple keys that compare equal to each other. (RRRRWWWWTTTTVVVVaaaallllHHHHaaaasssshhhhMMMMaaaapppp<<<<KKKK,,,,TTTT,,,,HHHH,,,,EEEEQQQQ>>>> will not accept a key that compares equal to any key already in the collection.) Equality is based on the comparison object and not on the ======== operator. PPPPeeeerrrrssssiiiisssstttteeeennnncccceeee Isomorphic. EEEExxxxaaaammmmpppplllleeeessss // // tvhmmrat.cpp // #include<rw/tvhmmap.h> #include<iostream.h> #include<rw/cstring.h> struct silly_hash{ unsigned long operator()(RWCString x) const { return x.length() * (long)x[0]; } }; int main(){ PPPPaaaaggggeeee 1111 RRRRWWWWTTTTVVVVaaaallllHHHHaaaasssshhhhMMMMuuuullllttttiiiiMMMMaaaapppp((((3333CCCC++++++++)))) RRRRWWWWTTTTVVVVaaaallllHHHHaaaasssshhhhMMMMuuuullllttttiiiiMMMMaaaapppp((((3333CCCC++++++++)))) RWCString trd = "Third"; RWTValHashMultiMap<RWCString,int,silly_hash,equal_to<RWCString> > contest; contest.insert("First", 7); contest.insert(trd,3); contest.insert(trd,6); // sssseeeellllffff contains two distinct values //equivalent to ttttrrrrdddd contest.insert("Second",2); contest.resize(8); cout << "The table is " << contest.fillRatio() * 100.0 << "% full<< endl; return 0; } Program Output: RRRReeeellllaaaatttteeeedddd CCCCllllaaaasssssssseeeessss The table is 50% full Class RRRRWWWWTTTTVVVVaaaallllHHHHaaaasssshhhhMMMMaaaapppp<<<<KKKK,,,,TTTT,,,,HHHH,,,,EEEEQQQQ>>>> offers the same interface to a collection that will not accept multiple keys that compare equal to each other. Class rrrrwwww____hhhhaaaasssshhhhmmmmuuuullllttttiiiimmmmaaaapppp<<<<KKKK,,,,TTTT,,,,HHHH,,,,EEEEQQQQ>>>> is the C++-standard collection that serves as the underlying implementation for this collection. PPPPuuuubbbblllliiiicccc TTTTyyyyppppeeeeddddeeeeffffssss typedef rw_hashmultimap<K,T,H,EQ> container_type; typedef container_type::iterator iterator; typedef container_type::const_iterator const_iterator; typedef container_type::size_type size_type; typedef pair <const K,T> value_type; typedef pair <const K,T>& reference; typedef const pair<const K,T>& const_reference; PPPPuuuubbbblllliiiicccc CCCCoooonnnnssssttttrrrruuuuccccttttoooorrrrssss RRRRWWWWTTTTVVVVaaaallllHHHHaaaasssshhhhMMMMuuuullllttttiiiiMMMMaaaapppp<<<<KKKK,,,,TTTT,,,,HHHH,,,,EEEEQQQQ>>>>(); Constructs an empty map. PPPPaaaaggggeeee 2222 RRRRWWWWTTTTVVVVaaaallllHHHHaaaasssshhhhMMMMuuuullllttttiiiiMMMMaaaapppp((((3333CCCC++++++++)))) RRRRWWWWTTTTVVVVaaaallllHHHHaaaasssshhhhMMMMuuuullllttttiiiiMMMMaaaapppp((((3333CCCC++++++++)))) RRRRWWWWTTTTVVVVaaaallllHHHHaaaasssshhhhMMMMuuuullllttttiiiiMMMMaaaapppp<<<<KKKK,,,,TTTT,,,,HHHH,,,,EEEEQQQQ>>>> (const rw_hashmultimap<K,T,H,EQ>& m); Constructs a map by copying all elements of mmmm. RRRRWWWWTTTTVVVVaaaallllHHHHaaaasssshhhhMMMMuuuullllttttiiiiMMMMaaaapppp<<<<KKKK,,,,TTTT,,,,HHHH,,,,EEEEQQQQ>>>> (const RWTValHashMultiMap<K,T,H,EQ>& rwm); Copy constructor. RRRRWWWWTTTTVVVVaaaallllHHHHaaaasssshhhhMMMMuuuullllttttiiiiMMMMaaaapppp<<<<KKKK,,,,TTTT,,,,HHHH,,,,EEEEQQQQ>>>> (const value_type* first, const value_type* last); Constructs a map by copying elements from the array of association pairs pointed to by ffffiiiirrrrsssstttt, up to, but not including, the association pointed to by llllaaaasssstttt. PPPPuuuubbbblllliiiicccc MMMMeeeemmmmbbbbeeeerrrr OOOOppppeeeerrrraaaattttoooorrrrssss RWTValHashMultiMap<K,T,H,EQ>& ooooppppeeeerrrraaaattttoooorrrr====(const RWTValHashMultiMap<K,T,H,EQ>& m); RWTValHashMultiMap<K,T,H,EQ>& ooooppppeeeerrrraaaattttoooorrrr====(const rw_hashmultimap<K,T,H,EQ>& m); Destroys all elements of self and replaces them by copying all associations from mmmm. bool ooooppppeeeerrrraaaattttoooorrrr========(const RWTValHashMultiMap<K,T,H,EQ>& m) const; bool ooooppppeeeerrrraaaattttoooorrrr========(const rw_hashmultimap<K,T,H,EQ>& m) const; Returns ttttrrrruuuueeee if self compares equal to mmmm, otherwise returns ffffaaaallllsssseeee. Two collections are equal if both have the same number of entries, and iterating through both collections produces, in turn, individual keys that compare equal to each other. PPPPuuuubbbblllliiiicccc MMMMeeeemmmmbbbbeeeerrrr FFFFuuuunnnnccccttttiiiioooonnnnssss void aaaappppppppllllyyyy(void (*fn)(const K&, T&, void*),void* d); void aaaappppppppllllyyyy(void (*fn)(const K&,const T&, void*), void* d) const; Applies the user-defined function pointed to by ffffnnnn to every association in the collection. This function must have one of the prototypes: PPPPaaaaggggeeee 3333 RRRRWWWWTTTTVVVVaaaallllHHHHaaaasssshhhhMMMMuuuullllttttiiiiMMMMaaaapppp((((3333CCCC++++++++)))) RRRRWWWWTTTTVVVVaaaallllHHHHaaaasssshhhhMMMMuuuullllttttiiiiMMMMaaaapppp((((3333CCCC++++++++)))) void yourfun(const K&, T& a, void* d); void yourfun(const K&, const T& a,void* d); Client data may be passed through parameter dddd. void aaaappppppppllllyyyyTTTTooooKKKKeeeeyyyyAAAAnnnnddddVVVVaaaalllluuuueeee(void (*fn)(const K&, T&, void*),void* d); void aaaappppppppllllyyyyTTTTooooKKKKeeeeyyyyAAAAnnnnddddVVVVaaaalllluuuueeee (void (*fn)(const K&,const T&,void*), void* d) const; This is a deprecated version of the aaaappppppppllllyyyy member above. It behaves exactly the same as aaaappppppppllllyyyy.... iterator bbbbeeeeggggiiiinnnn(); const_iterator bbbbeeeeggggiiiinnnn() const; Returns an iterator positioned at the first pair in self. size_type ccccaaaappppaaaacccciiiittttyyyy() const; Returns the number of buckets(slots) available in the underlying hash representation. See rrrreeeessssiiiizzzzeeee below. void cccclllleeeeaaaarrrr(); Clears the collection by removing all items from self. Each key and its associated item will have its destructor called. bool ccccoooonnnnttttaaaaiiiinnnnssss(const K& key) const; Returns ttttrrrruuuueeee if there exists a key jjjj in self that compares equal to kkkkeeeeyyyy, otherwise returns ffffaaaallllsssseeee. bool ccccoooonnnnttttaaaaiiiinnnnssss (bool (*fn)(const_reference,void*), void* d) const; PPPPaaaaggggeeee 4444 RRRRWWWWTTTTVVVVaaaallllHHHHaaaasssshhhhMMMMuuuullllttttiiiiMMMMaaaapppp((((3333CCCC++++++++)))) RRRRWWWWTTTTVVVVaaaallllHHHHaaaasssshhhhMMMMuuuullllttttiiiiMMMMaaaapppp((((3333CCCC++++++++)))) Returns ttttrrrruuuueeee if there exists an association aaaa in self such that the expression ((((((((****ffffnnnn))))((((aaaa,,,,dddd)))))))) is ttttrrrruuuueeee, otherwise returns ffffaaaallllsssseeee. ffffnnnn points to a user-defined tester function which must have prototype: bool yourTester(const_reference a, void* d); Client data may be passed through parameter dddd. iterator eeeennnndddd(); const_iterator eeeennnndddd() const; Returns an iterator positioned "just past" the last association in self. size_type eeeennnnttttrrrriiiieeeessss() const; Returns the number of associations in self. float ffffiiiillllllllRRRRaaaattttiiiioooo() const; Returns the ratio eeeennnnttttrrrriiiieeeessss(((())))/ccccaaaappppaaaacccciiiittttyyyy(((()))). bool ffffiiiinnnndddd(const K& key, Key& r) const; If there exists a key jjjj in self that compares equal to kkkkeeeeyyyy, assigns jjjj to rrrr and returns ttttrrrruuuueeee. Otherwise, returns ffffaaaallllsssseeee and leaves the value of rrrr unchanged. bool ffffiiiinnnndddd (bool (*fn)(const_reference,void*), void* d,pair<K,T>& r) const; If there exists an association aaaa in self such that the expression ((((((((****ffffnnnn))))((((aaaa,,,,dddd)))))))) is ttttrrrruuuueeee, assigns aaaa to rrrr and returns ttttrrrruuuueeee. Otherwise, returns ffffaaaallllsssseeee and leaves the value of kkkk unchanged. ffffnnnn points to a user- defined tester function which must have prototype: PPPPaaaaggggeeee 5555 RRRRWWWWTTTTVVVVaaaallllHHHHaaaasssshhhhMMMMuuuullllttttiiiiMMMMaaaapppp((((3333CCCC++++++++)))) RRRRWWWWTTTTVVVVaaaallllHHHHaaaasssshhhhMMMMuuuullllttttiiiiMMMMaaaapppp((((3333CCCC++++++++)))) bool yourTester(const_reference a, void* d); Client data may be passed through parameter dddd. bool ffffiiiinnnnddddVVVVaaaalllluuuueeee(const K& key, T& r) const; If there exists a key jjjj in self that compares equal to kkkkeeeeyyyy, assigns the item associated with jjjj to rrrr and returns ttttrrrruuuueeee. Otherwise, returns ffffaaaallllsssseeee and leaves the value of rrrr unchanged. bool ffffiiiinnnnddddKKKKeeeeyyyyVVVVaaaalllluuuueeee(const K& key, K& kr, T& tr) const; If there exists a key jjjj in self that compares equal to kkkkeeeeyyyy, assigns jjjj to kkkkrrrr, assigns the item associated with jjjj to trrrr,,,, and returns ttttrrrruuuueeee. Otherwise, returns ffffaaaallllsssseeee and leaves the values of kkkkrrrr and ttttrrrr unchanged. bool iiiinnnnsssseeeerrrrtttt(const K& key, const T& a); Adds kkkkeeeeyyyy with associated item aaaa to the collection. Returns ttttrrrruuuueeee. bool iiiinnnnsssseeeerrrrttttKKKKeeeeyyyyAAAAnnnnddddVVVVaaaalllluuuueeee(const K& key, const T& a); This is a deprecated version of the iiiinnnnsssseeeerrrrtttt member above. It behaves exactly the same as iiiinnnnsssseeeerrrrtttt. bool iiiissssEEEEmmmmppppttttyyyy() const; Returns ttttrrrruuuueeee if there are no items in the collection, ffffaaaallllsssseeee otherwise. size_type ooooccccccccuuuurrrrrrrreeeennnncccceeeessssOOOOffff(const K& key) const; Returns the number of keys jjjj in self that compares equal to kkkkeeeeyyyy. PPPPaaaaggggeeee 6666 RRRRWWWWTTTTVVVVaaaallllHHHHaaaasssshhhhMMMMuuuullllttttiiiiMMMMaaaapppp((((3333CCCC++++++++)))) RRRRWWWWTTTTVVVVaaaallllHHHHaaaasssshhhhMMMMuuuullllttttiiiiMMMMaaaapppp((((3333CCCC++++++++)))) size_type ooooccccccccuuuurrrrrrrreeeennnncccceeeessssOOOOffff (bool (*fn)(const_reference,void*),void* d) const; Returns the number of associations aaaa in self such that the expression((((((((****ffffnnnn))))((((aaaa,,,,dddd)))))))) is ttttrrrruuuueeee. ffffnnnn points to a user-defined tester function which must have prototype: bool yourTester(const_reference a, void* d); Client data may be passed through parameter dddd. bool rrrreeeemmmmoooovvvveeee(const K& key); Removes the first association with key jjjj in self such that jjjj compares equal to kkkkeeeeyyyy and returns ttttrrrruuuueeee. Returns ffffaaaallllsssseeee if there is no such association. bool rrrreeeemmmmoooovvvveeee(bool (*fn)(const_reference,void*), void* d); Removes the first association aaaa in self such that the expression ((((((((****ffffnnnn))))((((aaaa,,,,dddd)))))))) is ttttrrrruuuueeee and returns ttttrrrruuuueeee. Returns ffffaaaallllsssseeee if there is no such element. ffffnnnn points to a user-defined tester function which must have prototype: bool yourTester(const_reference a, void* d); Client data may be passed through parameter dddd. size_type rrrreeeemmmmoooovvvveeeeAAAAllllllll(const K& key); Removes all associations with key jjjj in self where jjjj compares equal to kkkkeeeeyyyy. Returns the number of items removed. PPPPaaaaggggeeee 7777 RRRRWWWWTTTTVVVVaaaallllHHHHaaaasssshhhhMMMMuuuullllttttiiiiMMMMaaaapppp((((3333CCCC++++++++)))) RRRRWWWWTTTTVVVVaaaallllHHHHaaaasssshhhhMMMMuuuullllttttiiiiMMMMaaaapppp((((3333CCCC++++++++)))) size_type rrrreeeemmmmoooovvvveeeeAAAAllllllll(bool (*fn)(const_reference,void*), void* d); Removes all associations aaaa in self such that the expression ((((((((****ffffnnnn))))((((aaaa,,,,dddd))))))))is ttttrrrruuuueeee. Returns the number of items removed. ffffnnnn points to a user-defined tester function which must have prototype: bool yourTester(const_reference a, void* d); Client data may be passed through parameter dddd. void rrrreeeessssiiiizzzzeeee(size_type sz); Changes the capacity of sssseeeellllffff by creating a new hashed multimap with a capacity of sssszzzz . rrrreeeessssiiiizzzzeeee then copies every element of sssseeeellllffff into the new container and finally swaps the internal representation of the new container with sssseeeellllffff. rw_hashmultimap<K,T,H,EQ>& ssssttttdddd(); const rw_hashmultimap<K,T,H,EQ>& ssssttttdddd() const; Returns a reference to the underlying C++-standard collection that serves as the implementation for self. This reference may be used freely, providing accessibility to the C++-standard interface and interoperability with other software components that make use of the C++-standard collections. RRRReeeellllaaaatttteeeedddd GGGGlllloooobbbbaaaallll OOOOppppeeeerrrraaaattttoooorrrrssss RWvostream& ooooppppeeeerrrraaaattttoooorrrr<<<<<<<<(RWvostream& strm, const RWTValHashMultiMap<K,T,H,EQ>& coll); RWFile& ooooppppeeeerrrraaaattttoooorrrr<<<<<<<<(RWFile& strm, const RWTValHashMultiMap<K,T,H,EQ>& coll); Saves the collection ccccoooollllllll onto the output stream ssssttttrrrrmmmm, or a reference to it if it has already been saved. PPPPaaaaggggeeee 8888 RRRRWWWWTTTTVVVVaaaallllHHHHaaaasssshhhhMMMMuuuullllttttiiiiMMMMaaaapppp((((3333CCCC++++++++)))) RRRRWWWWTTTTVVVVaaaallllHHHHaaaasssshhhhMMMMuuuullllttttiiiiMMMMaaaapppp((((3333CCCC++++++++)))) RWvistream& ooooppppeeeerrrraaaattttoooorrrr>>>>>>>>(RWvistream& strm, RWTValHashMultiMap<K,T,H,EQ>& coll); RWFile& ooooppppeeeerrrraaaattttoooorrrr>>>>>>>>(RWFile& strm, RWTValHashMultiMap<K,T,H,EQ>& coll); Restores the contents of the collection ccccoooollllllll from the input stream ssssttttrrrrmmmm. RWvistream& ooooppppeeeerrrraaaattttoooorrrr>>>>>>>>(RWvistream& strm, RWTValHashMultiMap<K,T,H,EQ>*& p); RWFile& ooooppppeeeerrrraaaattttoooorrrr>>>>>>>>(RWFile& strm, RWTValHashMultiMap<K,T,H,EQ>*& p); Looks at the next object on the input stream ssssttttrrrrmmmm and either creates a new collection off the heap and sets pppp to point to it, or sets pppp to point to a previously read instance. If a collection is created off the heap, then you are responsible for deleting it. PPPPaaaaggggeeee 9999